package com.webank.webase.node.mgr.deploy.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

import com.webank.webase.node.mgr.deploy.entity.TbConfig;

public interface TbConfigMapper {

    @Select({
        "select",
        TbConfigSqlProvider.ALL_COLUMN_FIELDS,
        "from tb_config",
        "where config_value = #{configValue,jdbcType=VARCHAR} order by id desc"
    })
    List<TbConfig> selectByConfigValue(@Param("configValue") String configValue);

    @Delete({
            "delete from tb_config", "where config_type = #{type,jdbcType=SMALLINT}"
    })
    int deleteByType(@Param("type") int type);

    @Select({
            "select",
            TbConfigSqlProvider.ALL_COLUMN_FIELDS,
            "from tb_config",
            "where config_type = #{type,jdbcType=SMALLINT} order by id desc"
    })
    List<TbConfig> selectByType(@Param("type") int type);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_config
     *
     * @mbg.generated
     */
    @Delete({
        "delete from tb_config",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_config
     *
     * @mbg.generated
     */
    @InsertProvider(type=TbConfigSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insertSelective(TbConfig record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_config
     *
     * @mbg.generated
     */
    @Select({
        "select",
        "id, config_name, config_type, config_value, create_time, modify_time",
        "from tb_config",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="config_name", property="configName", jdbcType=JdbcType.VARCHAR),
        @Result(column="config_type", property="configType", jdbcType=JdbcType.SMALLINT),
        @Result(column="config_value", property="configValue", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modify_time", property="modifyTime", jdbcType=JdbcType.TIMESTAMP)
    })
    TbConfig selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_config
     *
     * @mbg.generated
     */
    @UpdateProvider(type=TbConfigSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TbConfig record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table tb_config
     *
     * @mbg.generated
     */
    @Options(useGeneratedKeys = true,keyProperty="id",keyColumn = "id")
    @Insert({
    "<script>",
        "insert into tb_config (config_name, ",
        "config_type, config_value, ",
        "create_time, modify_time)",
        "values<foreach collection=\"list\" item=\"detail\" index=\"index\" separator=\",\">(#{detail.configName,jdbcType=VARCHAR}, ",
        "#{detail.configType,jdbcType=SMALLINT}, #{detail.configValue,jdbcType=VARCHAR}, ",
        "#{detail.createTime,jdbcType=TIMESTAMP}, #{detail.modifyTime,jdbcType=TIMESTAMP})</foreach></script>"
    })
    int batchInsert(java.util.List<TbConfig> list);
}